package com.shop.controller;

import com.shop.constant.MessageConstant;
import com.shop.entity.Result;
import com.shop.pojo.Address;
import com.shop.service.AddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
@Api(tags = "地址管理")
public class AddressController {
    @Reference
    private AddressService addressService;

    @GetMapping("/findAll")
    @ApiOperation("显示用户地址列表接口")
    @ApiImplicitParams({@ApiImplicitParam(dataType = "int",name = "uid",value = "用户id",required = true,example = "0")})
    private Result findAll(@RequestParam(required = true) Integer uid){
        List<Address> list=addressService.findAll(uid);
        return new Result(true, MessageConstant.QUERY_SUCCESS,list);
    }

    @PostMapping("/add")
    @ApiOperation("添加地址接口")
    public Result add(@RequestBody Address address){
        addressService.add(address);
        return new Result(true,MessageConstant.ADD_SUCCESS);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除地址接口")
    @ApiImplicitParams({@ApiImplicitParam(dataType = "int",name = "id",value = "地址id",required = true,example = "0")})
    public Result delete(@RequestParam(required = true) Integer id){
        addressService.delete(id);
        return new Result(true,MessageConstant.DELETE_SUCCESS);
    }
}
